package com.niit.data

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.serializer.SerializeConfig
import com.niit.utils.MyKafkaUtils
import org.apache.commons.lang.RandomStringUtils

import java.io.{File, FileWriter, PrintWriter}
import scala.util.Random

/**
 * @author 杨铭
 *         2022/11/19,14:55
 */
object makeData {

  def main(args: Array[String]): Unit = {
    val orderCategories = Array("20071712", "20071716", "20071745", "20081945",
      "20074513", "20084546", "20091213", "20091312", "20041213", "20041346")
    val random = new Random()
    while (true) {
      val days = Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
      val orderName = RandomStringUtils.randomAlphanumeric(6)
      val orderNum = random.nextInt(100)
      val i = random.nextInt(10)
      val orderCategory = orderCategories(i)
      var isCorrect = 'Z'
      if (i % 2 == 0) {
        isCorrect = 'Y'
      } else {
        isCorrect = 'N'
      }
      val year = (random.nextInt(20) + 1) + 2000
      val month = random.nextInt(11) + 1;
      if (month == 2) {
        if ((year % 4 == 0 && year % 100 != 0) || year % 100 == 0) {
          days(month) = 29
        }
      }
      var day = random.nextInt(30) + 1;
      if (days(month) < day) {
        day = days(month)
      }
      val date = year * 10000 + month * 100 + day
      val data1 = new data(orderCategory, orderName, orderNum, date, isCorrect)
      val value: String = JSON.toJSONString(data1, new SerializeConfig(true))

      MyKafkaUtils.send("orders", value)
            println(value)
      }

    }



}
